package com.jinhongone.pattern.structure.flyweight;

import java.util.HashMap;

/*
 * 享元工厂
 * */
public class BoxFactory {

    private HashMap<String, AbstractBox> map;

    //单例模式，私有构造方法
    private BoxFactory() {
        map = new HashMap<>();
        map.put("I", new IBox());
        map.put("L", new LBox());
        map.put("O", new OBox());
    }

    private static final BoxFactory instance = new BoxFactory();

    public static BoxFactory getInstance() {
        return instance;
    }

    public AbstractBox getBox(String index) {
        return map.get(index);
    }

}
